/**
 * 
 */
package edu.gatech.oad.mule;

import static org.junit.Assert.*;

import java.awt.Point;

import org.junit.Before;
import org.junit.Test;

import edu.gatech.oad.mule.model.GameStateMachine.GameState;

/**
 * @author Dale Avery
 * 
 */
public class OutfitterTest {

	private static final int OUTFITTER_X = 0;
	private static final int OUTFITTER_Y = 0;
	private static final int OUTFITTER_WIDTH = 15;
	private static final int OUTFITTER_HEIGHT = 15;
	private static final Point INSIDE = new Point(OUTFITTER_X / 2,
			OUTFITTER_Y / 2);
	private static final Point OUTSIDE = new Point(OUTFITTER_Y / 2,
			OUTFITTER_Y / 2);
	private static final char OUTFITTER_TYPE = MULE.FOOD;
	private static final char ALTERNATE_TYPE = MULE.ENERGY;

	private static final GameState STATE = GameState.DEVELOPMENT;
	private static final int ROUND = 1;
	private static final int TIME = 0;
	
	private Outfitter outfitter;
	private Player player;

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		outfitter = new Outfitter(OUTFITTER_X, OUTFITTER_Y, OUTFITTER_WIDTH,
				OUTFITTER_HEIGHT, OUTFITTER_TYPE);
		player = new Player();
	}

	/**
	 * Test method for
	 * {@link edu.gatech.oad.mule.Outfitter#interact(edu.gatech.oad.mule.Player, edu.gatech.oad.mule.model.GameStateMachine.GameState, int, int)}
	 * .
	 */
	@Test
	public void testInteract() {
		// Player interacting with Outfitter.
		outfitter.interact(player, STATE, ROUND, TIME);
		// Has no mule, should be no transaction or money loss.
		int money = player.getWallet().getMoney();
		assertTrue(player.getMULE() == null);
		assertTrue(player.getWallet().getMoney() == money);
		
		// Has a blank mule and plenty of money, mule should be outfitted and money reduced.
		player.setMULE(new MULE());
		outfitter.interact(player, STATE, ROUND, TIME);
		assertTrue(player.hasMule());
		assertTrue(player.getMULE().getType() == OUTFITTER_TYPE);
		assertTrue(player.getWallet().getMoney() < money && player.getWallet().getMoney() > 0);
		
		// Has a mule with a different type.  Should not alter type.
		money = player.getWallet().getMoney();
		MULE mule = new MULE();
		mule.outfit(ALTERNATE_TYPE);
		player.setMULE(mule);
		outfitter.interact(player, STATE, ROUND, TIME);
		assertTrue(player.hasMule());
		assertTrue(player.getMULE().getType() == ALTERNATE_TYPE);
		assertTrue(player.getWallet().getMoney() == money);
		
		// Player has a mule but not enough money to outfit.  Should be no transaction.
		player.getWallet().setMoney(0);
		money = 0;
		player.setMULE(new MULE());
		outfitter.interact(player, STATE, ROUND, TIME);
		assertTrue(player.hasMule());
		assertTrue(player.getMULE().getType() == MULE.UNFITTED);
		assertTrue(player.getWallet().getMoney() == money);
	}

}
